package com.cat.greedyAlgorithm;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/partition-string-into-substrings-with-values-at-most-k/description/
 * @create 2025/10/10 11:53
 * @since JDK17
 */

public class Solution71 {
    public int minimumPartition(String s, int k) {
        char[] arr = s.toCharArray();
        int n = arr.length, ans = 1;
        long sum = 0;
        for (int i = 0; i < n; i++) {
            int num = arr[i] - '0';
            if (num > k) {
                return -1;
            }
            sum = sum * 10 + num;
            if (sum > k) {
                ans++;
                sum = num;
            }
        }

        return ans;
    }
}
